<admintpl file="header" />
<style type="text/css">
.gift_input{
	width:50px;}
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('goods/index')}">{:lang('ADMIN_GOODS_INDEX')}</a></li>
			<li><a href="{:url('goods/add')}">{:lang('ADMIN_GOODS_ADD')}</a></li>
            <li><a href="{:url('goods/edit', array('id' => I('request.id/s',''),'type'=>I('request.type')))}">{:lang('ADMIN_GOODS_EDIT')}</a></li>
            <li><a href="{:url('goods/attribute', array('id' => I('request.id', ''),'type'=>I('request.type')))}">{:lang('GOODS_ATTRIBUTE')}</a></li>
            <li class="active"><a href="{:url('goods/ability', array('id' => I('request.id', ''),'type'=>I('request.type')))}">{:lang('GOODS_ABILITY')}</a></li>
		</ul>
		<form  action="{:url('Goods/ability_post')}"  method="post" class="form-horizontal js-ajax-form">
           	<input type="hidden" name="goods_id" value="{:input('request.id', 0, 'intval')}" />
           	<input type="hidden" name="attrbute" value="<php>echo count($attrbute);</php>" />
            <input type="hidden" name="goodtype" value="{$goods_type}">
			<table class="table table-hover table-bordered">
				<thead>
					<tr>
                    	<foreach name="attrbute" item="vo">
                        	<th>{$vo.att_name}</th>
                        </foreach>
                        <th>商品编码</th>
                        <if condition="$goods_type eq 1">
                           <th width="200px">兑换条件</th>
                        <else/>
                           <th>{:lang('PRICE')}</th>
                        </if>
                      <!-- <foreach name="grade" item="vo">
                       		<input type="hidden" name="member_grade[]" value="{$vo.member_grade_id}" />
                        	<th>{$vo.grade_name}</th>
                        </foreach>
                        <foreach name="area" item="vo">
                       		<input type="hidden" name="area_id[]" value="{$vo.id}" />
                        	<th>{$vo.area}</th>
                        </foreach>-->
                        <th>{:lang('STOCK')}</th>
                        <th>商品图片</th>
						<th width="120px"><a class="btn btn-primary js-ajax-submit" href="javascript:void(0)" onClick="addAbility()">{:lang('ADD_ABILITY')}</a></th>
					</tr>
				</thead>
				<tbody>
					<foreach name="results" item="vo">
                         <input type="hidden" name="ability_id[]" value="{$vo.id}">
					<tr class="ability">
                    	<foreach name="attrbute" item="ivo">
							<td><input type="text" class="short_input" name="name_{$key + 1}[]" placeholder="请输入属性值{$key + 1}" value="<php>echo $vo['ability_'.($key+1)];</php>" /></td>
                        </foreach>
                        <td>  
                        <input type="text" class="short_input" name="encoding[]" placeholder="请输入商品编码" value="{$vo.encoding}" /></td>
						<td>
                          <if condition="$goods_type eq 1">
                          <!--礼品-->
                            <input type="text" class="gift_input" name="read_num[]" placeholder="阅读数" value="{$vo['read_num']}"/>
                                <select class="gift_input"  name="rel[]" >
                                    <option value="0" <if condition="$vo['rel'] eq 0">selected</if>>或</option>
                                    <option value="1" <if condition="$vo['rel'] eq 1">selected</if>>和</option>
                                </select>
                            <input type="text" class="gift_input" name="buy_num[]"  value="{$vo['buy_num']}" placeholder="购买数" />                         <else/>
							<!--商品-->
                       		 <input type="text" class="short_input" name="sale_price[]" placeholder="请输入商品价格" value="{$vo.sale_price}" /></td>
                         </if>
                        
                    <!--    <foreach name="vo['sub']" item="val">
							<td><input type="text" class="short_input" name="price[]" placeholder="请输入价格" value="{$val.price}" /></td>
                        </foreach>
                        <foreach name="vo['area']" item="svo">
             		    <td><input type="text" class="short_input" name="area_price[]" placeholder="请输入价格"  value="{$svo['area_price']}"/></td>
          				</foreach>-->
                        <td><input type="text" class="short_input" name="inventory[]" placeholder="请输入库存" value="{$vo.inventory}" /></td>
                        <td>
                            <input type="hidden" name="image[]" id="image{$vo['id']}" value="{$vo.image}">
                            <img height="36" src="{$vo.image}" class="preview" id="image{$vo['id']}_preview" />
                            <a class="btn btn-primary" onClick="upload_one_image('商品图片', '#image{$vo['id']}')">{:lang("UPLOAD")}</a>
                        </td>
                        <td>
                             <a href="javascript:parent.open_iframe_dialog('{:url('Admin/Goods/vipprice',array('num'=>1,id=>$vo['id'],'type'=>$goods_type))}','编辑会员价格',{}, '600px', '660px')">编辑会员价格</a><br>
                        	 <!--<a href="javascript:parent.open_iframe_dialog('{:url('Admin/Goods/area',array('area'=>1,'id'=>$vo['id']))}','编辑地区价格',{}, '600px', '660px')">编辑地区价格</a><br>
               				 <a href="javascript:parent.open_iframe_dialog('{:url('Admin/Goods/price',array('num'=>1,id=>$vo['id']))}','编辑会员价格',{}, '600px', '660px')">编辑会员价格</a><br>
-->                             <a class="js-ajax-delete" data-msg="确定删除么？" href="{:url('Goods/del_ability',array('id'=>$vo['id'],goods=>$vo['goods_id']))}">删除</a>
						</td>
					</tr>
					</foreach>
				</tbody>
			</table>
			<div class="form-actions">
				<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
				<a class="btn" href="javascript:history.back(-1);">{:lang('BACK')}</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
    <script type="text/javascript">
		var gtype="{$goods_type}"
		function addAbility(){
			var b=$('.ability').length;
			if(gtype==1){
				//礼品
				var html = $('#add_abitype'+b).html();
			}else{
				//商品
				var html = $('#add_ability'+b).html();
			}
			$(".table tbody").append(html);
		}
	</script>
	<php>  
    	//礼品
        
		if($goods_type==1){
    	for($a=0;$a<100;$a++){
    </php>
    
    <script type="text/html" id="add_abitype{$a}">
		<tr class="ability">
			<foreach name="attrbute" item="vo">
				<td><input type="text" class="short_input" name="name_{$key + 1}[]" placeholder="请输入属性值{$key + 1}" /></td>
			</foreach>
			<td>
			<input type="hidden" name="nember[]" id="vip{$a}" value="">
			<input type="text" class="short_input" name="encoding[]" placeholder="请输入商品编码" /></td>
			<td><input type="text" class="gift_input" name="read_num[]" placeholder="阅读数" />
				<select class="gift_input" name="rel[]">
					<option value="0">或</option>
					<option value="1">和</option>
				</select>
			<input type="text" class="gift_input" name="buy_num[]" placeholder="购买数" /></td>
			<td><input type="text" class="short_input" name="inventory[]" placeholder="请输入库存" /></td>
			<td >
			   <input type="hidden" name="image[]"  id="images{$a}" value="{:C('GOODS_DEFAULT')}">
               <img height="36" src="" class="preview isHide" id="images{$a}_preview" />
			   <a class="btn btn-primary" onClick="upload_one_image('商品图片','#images{$a}')">{:lang("UPLOAD")}</a>
             </td>
			 <td>
			    <a href="javascript:parent.open_iframe_dialog('{:url('Admin/Goods/vipprice',array('num'=>'vip'.$a,'type'=>$goods_type))}','添加会员价格',{}, '600px', '660px')">添加会员价格</a><br>
            	<a href="javascript:void(0)" onClick="$(this).closest('tr').remove();">移除</a>
			</td>
			   </foreach>
			
		</tr>
	</script>
    <script>
		window.onstorage = function(text) {
			if(text.key=='text'  ){
				$('#'+text.key).val(text.newValue);
			}else{
				$('#'+text.key).val(text.newValue);
			}
			sessionStorage.clear()
		};
	</script>
    <php>}}</php>
    
    
    <php> 
    	//商品  
    	if($goods_type==2){
    	for($a=0;$a<100;$a++){
    </php>
    <script type="text/html" id="add_ability{$a}">
		<tr class="ability">
			<foreach name="attrbute" item="vo">
				<td><input type="text" class="short_input" name="name_{$key + 1}[]" placeholder="请输入属性值{$key + 1}" /></td>
			</foreach>
			<td>
			<input type="hidden" name="nember[]" id="vip{$a}" value="">
			<input type="text" class="short_input" name="encoding[]" placeholder="请输入商品编码" /></td>
			<td><input type="text" class="short_input" name="sale_price[]" placeholder="请输入商品价格" /></td>
			<td><input type="text" class="short_input" name="inventory[]" placeholder="请输入库存" /></td>
			<td >
			   <input type="hidden" name="image[]"  id="images{$a}" value="{:C('GOODS_DEFAULT')}">
               <img height="36" src="" class="preview isHide" id="images{$a}_preview" />
			   <a class="btn btn-primary" onClick="upload_one_image('商品图片','#images{$a}')">{:lang("UPLOAD")}</a>
             </td>
			 <td>
			    <a href="javascript:parent.open_iframe_dialog('{:url('Admin/Goods/vipprice',array('num'=>'vip'.$a,'type'=>$goods_type))}','添加会员价格',{}, '600px', '660px')">添加会员价格</a><br>
            	<a href="javascript:void(0)" onClick="$(this).closest('tr').remove();">移除</a>
			</td>
			   </foreach>
			
		</tr>
	</script>
    <script>
		window.onstorage = function(text) {
			if(text.key=='text'  ){
				$('#'+text.key).val(text.newValue);
			}else{
				$('#'+text.key).val(text.newValue);
			}
			sessionStorage.clear()
		};
	</script>
    <php>}}</php>
    	
</body>
</html>